/**
 * 
 */
package com.jonosoft.photocast.viewer.web.client;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import com.jonosoft.photocast.viewer.web.client.photocast.Photocast;
import com.jonosoft.photocast.viewer.web.client.photocast.PhotocastItem;
import com.jonosoft.photocast.viewer.web.client.ui.LibraryImage;

/**
 * TODO Add description ImageSet
 * (com.jonosoft.photocast.viewer.web.client.ImageSet)
 * 
 * @author jon
 * 
 */
public class LibraryImageMap extends HashMap {
	
	private static String ILLEGAL_ARGUMENT_EXCEPTION = "Argument must be of type LibraryImage.";

	public static LibraryImageMap createFromPhotocast(Photocast photocast) {
		LibraryImageMap libraryImageMap = new LibraryImageMap();

		libraryImageMap.clear();
		
		Iterator i = photocast.getPhotocastItems().iterator();
		
		while (i.hasNext())
			libraryImageMap.add(LibraryImage
			        .createFromPhotocastItem((PhotocastItem) i.next()));

		return libraryImageMap;
	}
	
	public Object add(LibraryImage libraryImage) {
		return put(libraryImage.getGuid(), libraryImage);
	}
	
	public void addAll(Collection libraryImageCollection) {
		Iterator collectionIterator = libraryImageCollection.iterator();
		HashMap map = new HashMap();
		
		while (collectionIterator.hasNext())
			if (!(collectionIterator.next() instanceof LibraryImage))
				throw new IllegalArgumentException(ILLEGAL_ARGUMENT_EXCEPTION);

		super.putAll(map);
	}

	public Object put(Object guid, Object libraryImage) {
		if (libraryImage instanceof LibraryImage) {
			LibraryImage limg = (LibraryImage) libraryImage;
			return super.put(guid, limg);
		} else
			throw new IllegalArgumentException(ILLEGAL_ARGUMENT_EXCEPTION);}

	public void putAll(Map arg0) {
	    // TODO Auto-generated method stub
	    super.putAll(arg0);
    }

}
